class Solution
{
public:
    vector<int> findAnagrams(string s, string p)
    {
        int n = s.size(), m = p.size();
        if (m > n)  return {};
        vector<int> ans, cnt_s(26), cnt_p(26);
        int i = 0;
        for (; i < m; i++)
        {
            cnt_s[s[i] - 'a']++;
            cnt_p[p[i] - 'a']++;
        }
        if (cnt_p == cnt_s)  ans.push_back(0);
        for (; i < n; i++)
        {
            cnt_s[s[i] - 'a']++;
            cnt_s[s[i - m] - 'a']--;
            if (cnt_p == cnt_s)  ans.push_back(i - m + 1);
        }
        return ans;
    }
};